<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE HTML >
<%@include file="/WEB-INF/jsp/include/background.jsp"%>
<html>
<head>
<meta charset=UTF-8>
<title>添加教师页面</title>
<link rel="stylesheet" type="text/css" href="<%=css%>/common.css"/>
<link rel="stylesheet" type="text/css" href="<%=css%>/main.css"/>
<script type="text/javascript">
$(document).ready(function() {
	$("#goBack").click(function(){
		$("#form2").submit();
	});
	
	//保存按钮
	$("#saveButton").click(function() {
		var name = $("#name").val();
		var sex = $("#sex").val();
		var headpath = $("#headpath").val();
		var phone = $("#phone").val();
		var recommend = $("input[name='recommend']:checked").val();
		var videopath = $("#videopath").val();
		var torder = $("#torder").val();
		var grade = "";
		$('input[name="grade"]:checked').each(function(){ 
		    grade+=$(this).val()+','; 
		});
		if (grade.length > 0) { 
		    grade = grade.substring(0,grade.length - 1); 
		}
		var subject = "";
		$('input[name="subject"]:checked').each(function(){ 
		    subject+=$(this).val()+','; 
		});
		if (subject.length > 0) { 
			subject = subject.substring(0,subject.length - 1); 
		}
		var quyu = "";
		$('input[name="quyu"]:checked').each(function(){ 
		    quyu+=$(this).val()+','; 
		});
		if (quyu.length > 0) { 
			quyu = quyu.substring(0,quyu.length - 1); 
		}
		$.ajax({
			url : "<%=pre%>/b_teacher/insert<%=suf%>",
			type : 'post',
			dataType : 'html',
			data : {name:name,sex:sex,phone:phone,torder:torder,subject:subject,grade:grade,quyu:quyu,videopath:videopath,headpath:headpath,recommend:recommend},
			success : function(data, status) {
				if (status == 'success') {
					if (data == '1') {
						var timer;
						art.dialog({
							content : '<span style="color:#f00">插入成功！</span>',
							init : function() {
								var that = this, i = 1;
								var fn = function() {
									!i && that.close();
									i--;
								};
								timer = setInterval(fn, 1000);
								fn();
							},
							close : function() {
								clearInterval(timer);
								window.location.href="<%=pre%>/b_teacher/index<%=suf%>";
							}
						}).show();	
					} else {
						art.dialog.tips('<span style="color:#f00">插入失败！</span>', 1);
					}
				}
			},
			error : function(xhr, textStatus,
					errorThrown) {
				art.dialog.tips('<span style="color:#f00">插入失败！</span>', 1);
			}
		});
	});
	
	//上传图片
	$("#uploadFile").live('change',function(){
		var picFile = $("#uploadFile").val();
		var wjjname = "teacher";
		if(picFile == ""){
			art.dialog.alert("请选择文件!");
			return;
		}
		else{
			var strFilter = ".jpeg|.gif|.jpg|.png|";
			if(picFile.indexOf(".") > -1){
				var p = picFile.lastIndexOf(".");
				var strPostfix = picFile.substring(p,picFile.length) + '|';
				strPostfix = strPostfix.toLowerCase();
				if(strFilter.indexOf(strPostfix) > -1){
					$.ajaxFileUpload({
						url: '<%=pre%>/b_com/fileupload<%=suf%>', 
						data:{wjjname:wjjname},
						type: 'post',
						fileElementId: 'uploadFile',
						dataType:'json', //返回值类型，一般设置为json、application/json
						success: function(data, status){ 
				            	if(data.ret == 1){
				            		$("#headpath").val(data.path);
				            		$("#imgheadpath").attr("src","<%=upload%>/"+ data.path);
				            	}
				            	else{
				            		art.dialog.alert("上传失败！");
				            	}
				            },
				            error: function(data, status, e){ 
				            	art.dialog.tips('<span style="color:#f00">上传失败，请重传！</span>', 1);
				            }
					});
				}else{
					art.dialog.alert("请选择：图片格式的文件！");
				}
			}
		}
	});
	
});
</script>
</head>
<body>
<div class="crumb-wrap">
	<div class="crumb-list">
		<i class="icon-font"></i>
		<a href="index.html">首页</a>
		<span class="crumb-step">&gt;</span>
		<span class="crumb-name">教师管理</span>
		<span class="crumb-step">&gt;</span>
		<span class="crumb-name">教师添加</span>
	</div>
</div>
<form id="form2" action="<%=pre%>/teacher/index<%=suf%>" method="post"></form>
<div class="result-wrap">
	<div class="result-content">
		<table class="insert-tab" width="100%">
			<tr>
				<td style="width:12%">教师名称:</td>
				<td style="width:40%">
					<input id="name" name="name" style="width: 150px" type="text" />
					<span class="red" id="nametip">*</span>
				</td>
				<td style="width:10%">性别:</td>
				<td style="width:40%">
					<select id="sex" name="sex">
						<option>男</option>
						<option>女</option>
					</select>
				</td>
			</tr>
			<tr>
				<td>电话：</td>
				<td>
					<input type="text" name="phone" id="phone" style="width:150px" />
				</td>
				<td>显示顺序：</td>
				<td>
					<input type="text" name="torder" id="torder" style="width:150px" />
				</td>
			</tr>
			<tr>
				<td>教学科目：</td>
				<td colspan="3">
					<c:forEach items="${listSubject}" var="obj">
						<input name="subject" type="checkbox" value="${obj.name }" />${obj.name }
					</c:forEach>
				</td>
			</tr>
			<tr>
				<td>教学年级：</td>
				<td colspan="3">
					<c:forEach items="${listGrade}" var="obj">
						<input name="grade" type="checkbox" value="${obj.name }" />${obj.name }
					</c:forEach>
				</td>
			</tr>
			<tr>
				<td>地址：</td>
				<td colspan="3">
					<c:forEach items="${listQuyu}" var="obj">
						<input name="quyu" type="checkbox" value="${obj.name }" <c:if test="${obj.name == '基础' }">checked='checked'</c:if>  />${obj.name }
					</c:forEach>
				</td>
			</tr>
			<tr>
				<td>腾讯视频vid：</td>
				<td colspan="3">
					<input type="text" name="videopath" id="videopath" style="width:80%" />
					<span style="color:red" id="videopathtip">*</span>
				</td>
			</tr>
			<tr>
				<td>是否首页推荐：</td>
				<td colspan="3">
					<input type="radio" name="recommend" value="2" checked="true"/>否
					<input type="radio" name = "recommend" value="1"/>是
				</td>
			</tr>
			
			<tr>
				<td>选择头像：</td>
				<td colspan="3">
					<input id="uploadFile" name="uploadFile" type="file" />
					<input type="hidden" id="headpath" name="headpath">
					<img id="imgheadpath" width="120px" height="120px">
					<span style="color:red"  width="200px">(建议图片大小：220*220px)</span>
				</td>
			</tr>
			<tr>
				<td>
					<input type="button" value="保存" class="button" id="saveButton" />
					<a href="<%=pre%>/b_teacher/index<%=suf%>" style="padding-left:10px">返回</a>
				</td>
				<td colspan="3"></td>
			</tr>
		</table>
	</div>
</div>
</body>
</html>